<template>
  <view class="pages w-100 m-h-100 bg-co-f6">
    <view class="w-702 bor-radius-16 card bg-co-white mar-0-auto" style="z-index: 9">
      <view class="title">绑定的支付宝账号</view>
      <view class="p-l-24 p-r-24 item flex-row-between f-s-28 co-33">
        <view class="left">姓名</view>
        <u-input
          v-model="params.ali_realname"
          type="text"
          maxlength="24"
          placeholder="请输入真实姓名"
          border="none"
        />
      </view>
      <view class="p-l-24 p-r-24 item flex-row-between f-s-28 co-33">
        <view class="left">支付宝账号</view>
        <u-input
          v-model="params.ali_account"
          type="text"
          placeholder="请输入支付宝账号"
          border="none"
        />
      </view>
    </view>

    <view
      v-if="params.ali_account"
      class="w-702 mar-0-auto submit-btn flex-center bg-co-blue mar-t-30 f-s-32 co-white"
      @click="submit"
    >
      保存
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'
import { showToast, navigateTo, navigateBack, showLoading, hideLoading, redirectTo } from '@/utils'
import { useMemberStore } from '@/stores'
import { updateAlipayApi } from '@/services/my/user'
import { getUserInfoApi } from '@/services/my/login/index.ts'
const store = useMemberStore().userInfo
onShow(() => {
  // params.value.ali_account = store.user.ali_account
  // params.value.ali_realname = store.user.ali_realname
  // console.log(store)
})
const params = ref({
  ali_account: '',
  ali_realname: '',
})
async function submit() {
  const res = await updateAlipayApi(params.value)
  console.log(res)
  getUserInfo()
  showToast(res.msg || res.message)
  navigateBack()
}
async function getUserInfo() {
  let res = await getUserInfoApi()
  store.user.ali_account = res.data.center.user.ali_account
  store.user.ali_realname = res.data.center.user.ali_realname
}
</script>

<style scoped lang="scss">
.pages {
  padding-top: 20rpx;
  font-family: PingFang SC, PingFang SC;

  .card {
    position: relative;

    .title {
      font-size: 32rpx;
      font-weight: 500;
      color: #333333;
      padding: 29rpx 0 0 20rpx;
    }

    .item {
      height: 108rpx;
      border-bottom: 1rpx solid #f6f6f6;

      .left {
        width: 180rpx;
      }
    }
  }

  .submit-btn {
    height: 75rpx;
    border-radius: 75rpx;
  }
}
</style>
